<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<div class="button_area">
	<a class="button" id="export_all">导出全部</a>
	<a class="button" id="export">导出</a>
	<a href="employee/employee.info.action" class="button">添加</a>
</div>
<div class="filter_area">
	<s:form>
		<tr>
			<td>
				<table>
					<s:textfield label="员工姓名" id="employeeName" name="filter.employeeName" size="10"></s:textfield>
				</table>
			</td>
			<td>
				<table>
					<s:select label="部门" name="filter.deparment" id="employeeName"
						list="departments" 
						listKey="dictionaryId" listValue="dictionaryName" headerKey="" headerValue="全部" ></s:select>
				</table>
			</td>

			<td>
				<table>
					<s:textfield label="手机号码" id="phoneNumber" name="filter.phoneNumber"
						size="10"></s:textfield>
				</table>
			</td>	

			<td width="20px"></td>
			<td style="padding-bottom: 6px" valign="bottom">
				<a href="javascript:void(0)" onclick="GridOption.doSearch()">搜索</a>
			</td>
		</tr>

	</s:form>
</div>
<div id="dialog" title="请选择需要导出的列" style="display: none; width: 100%">
<table width="600px" class="form_table">
<tr>
<s:iterator value="fields" status="status">
	<td><input type="checkbox" checked="checked" name="fields" value="<s:property value="fieldId"/>"></td><td><s:property value="label"/></td>
	<s:if test="(#status.index+1)%6==0"></tr><tr></s:if>
</s:iterator>
</tr>
</table>
</div>
<script type="text/javascript">
var GridOption={        
			url:'employee/employeeList.action?'+$('form').serialize(),
     		datatype: 'json',  
     		jsonReader:{ root: "dataRows"},   
    		colModel:[       
       			{label:'id',name:'employeeId',index:'employeeId',key:true, hidden:true},     
       			{label:'员工姓名',name:'employeeName',index:'employeeName',required:true, width:100,editable:false,formatter:'showlink', formatoptions:{baseLinkUrl:'employee/employee.info.action'}},     
        		{label:'部门',name:'department.dictionaryName',index:'department.dictionaryName', width:100,editable:false},       
        		{label:'手机号码',name:'phoneNumber',index:'phoneNumber', width:100,editable:false},       
        		{label:' ',name:'del', width:100,align:'center',sortable:false}
     		],     
     		imgpath: '../theme/images/jqgrid/',      
    		pager: "#pjmap",   
      		multiselect: true,     
     		sortname: 'employeeId',     
      		viewrecords: true,     
      		sortorder: "desc",     
      		jsonReader: {     
	      		root: "dataRows",
	      		repeatitems : false
     		},
     		gridComplete: function(){
				var ids = jQuery("#list").jqGrid('getDataIDs');
				for(var i=0;i < ids.length;i++){
					var cl = ids[i];
					var data=jQuery("#list").jqGrid('getRowData',cl);
					if(data.deleted=='true'){
						if(!data.loginId.startWith('<img') && !data.loginId.startWith('<IMG')){
							cd='<img style="border:1px" src="theme/images/del.gif" title=""/>'+data.loginId;
						}else{
							cd=data.loginId;
						}
						sc= "<a href='javascript:void(0)' onclick=\"GridOption.doRedeleted("+cl+");\">恢复</a>";
						jQuery("#list").jqGrid('setRowData',ids[i],{loginId:cd,del:sc});
					}else{
						

						sc= "<a href='javascript:void(0)' onclick=\"GridOption.doDelete("+cl+");\">删除</a>";
						jQuery("#list").jqGrid('setRowData',ids[i],{del:sc});
					}
				}
			},
    		width:$(document).width()-80,
    		height: $(document).height()-160,
    		doDelete:function(id){
    			var data=jQuery("#list").jqGrid('getRowData',id);
    			$("#list").delGridRow(id,{url:'employee/employeeDelete.action',caption:'请确认',msg:'确认删除 "'+data.employeeName+'" 吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
    			
    		},
    		doRedeleted:function(id){
    			var data=jQuery("#list").jqGrid('getRowData',id);
    			$("#list").delGridRow(id,{url:'employee/employeeDelete.action',caption:'请确认',msg:'确认恢复 "'+data.employeeName+'" 吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
    			$("#list").trigger("reloadGrid");
    		},
    		doSearch:function(){
    			$("#list").setGridParam({url:"employee/employeeList.action?"+$('form').serialize()});
      			$("#list").trigger("reloadGrid");
    		}
    };

     $(document).ready(function(){          
    	$('#createdDate_from').datepicker();
    	$('#createdDate_to').datepicker();
    	$('#export').click(function(){
    		window.open('employee/export');
  	
  		});
    	$('#export_all').click(function(){
  			$("#dialog").dialog({ 
  						width:700,
  						buttons: { 
  							"确认":function() {
  								var values="";
  								$('input[name=fields]:checked').each(function(i,checkbox){
  									if(i==0){
  										values=checkbox.value;
  									}else{
  										values=values+","+checkbox.value;
  									}
  								});
  								$(this).dialog("close"); 
  								if(values==""){alert("请选择导出的列");return;}
								window.open('employee/export.all.action?fieldIds='+values);
  							},
  							"取消":function(){
  								$(this).dialog("close");
  							}
  						} 
  			});
  	
  		});
	})
</script>
